<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="__STATIC__/template/lib/html5shiv.js"></script>
    <script type="text/javascript" src="__STATIC__/template/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="__STATIC__/template/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->


    <title>产品列表</title>
    <!--<link rel="stylesheet" href="__STATIC__/template/lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">-->
</head>
<body class="pos-r">
<style>
    #DataTables_Table_0_info {
        display: none;
    }
    #DataTables_Table_0_paginate{
        display: none;
    }
    /*分页样式*/
    .pagination{text-align:center;margin-top:20px;margin-bottom: 20px;}
    .pagination li{margin:0px 10px; border:1px solid #e6e6e6;padding: 3px 8px;display: inline-block;}
    .pagination .active{background-color: #46A3FF;color: #fff;}
    .pagination .disabled{color:#aaa;}
    a:hover{color: #ff081f; /*鼠标在a上面时,变蓝色*/}
</style>
<!--<div class="pos-a" style="width:200px;left:0;top:0; bottom:0; height:100%; border-right:1px solid #e5e5e5; background-color:#f5f5f5; overflow:auto;">
	<ul id="treeDemo" class="ztree"></ul>
</div>-->
<div style="">
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span> 产品管理
        <span class="c-gray en">&gt;</span> 产品列表
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
    </nav>
    <div class="page-container">
        <div class="text-c">
             <span class="select-box" style="width:120px;">
				  <select class="select" id="opt" name="opt">
                      <option value="1">商品分类搜索</option>
                      <option value="2">商品标题搜索</option>
                      <option value="3">商品板块搜索</option>
                      <option value="4">商品价格范围</option>
                  </select>
			</span>
            <span class="select-box" style="width:120px;" id="type_s">
				  <select class="select" id="goodsType" name="goodsType">
                      {notempty name='gt_id'}
                          {foreach name="category" id="v"}
                          <option value="{$v.id}" {$v.id==$gt_id ? 'selected = selected':'' }>{$v.name}</option>
                          {/foreach}
                      {else /}
                          {foreach name="category" id="v"}
                          <option value="{$v.id}">{$v.name}</option>
                          {/foreach}
                      {/notempty}
                  </select>
			</span>
            <span class="select-box" style="width:120px;display: none" id="block_s" >
				  <select class="select" id="gb_id" name="gb_id">
                      {notempty name='gb_id'}
                          {foreach name="block" id="v"}
                          <option value="{$v.id}" {$v.id==$gb_id ? 'selected = selected':'' }>{$v.name}</option>
                          {/foreach}
                      {else /}
                          {foreach name="block" id="v"}
                          <option value="{$v.id}">{$v.name}</option>
                          {/foreach}
                      {/notempty}
                  </select>
			</span>
            <input type="text" value="{$goods_title ? $goods_title : ''; }" class="input-text" style="width:250px;display: none" placeholder="商品标题" id="goods_title" name="goods_title" >
           <span id="price" style="display:none;">
              <input type="text" value="{$start_price? $start_price : ''; }" class="input-text" style="width:250px;" placeholder="价格最低值" id="start_price" name="start_price" >
               -
               <input type="text" value="{$end_price ? $end_price : ''; }" class="input-text" style="width:250px;" placeholder="价格最高值" id="end_price" name="end_price" >
           </span>
            <button type="submit" class="btn btn-success" id="find"  name="submit" >
                <i class="icon-search"></i> 搜产品
            </button>

        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20" id="load">
			<span class="l">
				<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius">
                    <i class="Hui-iconfont" >&#xe6e2;</i> 批量回收
                </a>
			</span> <span class="r">共有数据：<strong>{$count}</strong> 条</span>
        </div>
        <div class="mt-20" id="replace">
            <table class="table table-border table-bordered table-bg table-hover table-sort" >
                <thead>
                <tr class="text-c">
                    <th width="40">
                        <input name="" type="checkbox" value="0" class="productCheck">
                    </th>
                    <th width="50">商品表ID</th>
                    <th width="100">淘宝/天猫商品ID</th>
                    <th width="60">缩略图</th>
                    <th width="100">商品标题</th>
                    <th width="60">原价</th>
                    <th width="60">折价</th>
                    <th width="60">折率</th>
                    <th width="60">券后价</th>
                    <th width="60">优惠券</th>
                    <th width="60">佣金</th>
                    <th width="60">佣率</th>
                    <th width="80">月销量</th>
                    <th width="80">店铺</th>
                    <th width="80">浏览量</th>
                    <th width="80">所属分类</th>
                    <th width="100">所属板块</th>
                    <th width="100">添加时间</th>
                    <th width="60">发布状态</th>
                    <th width="60">精选</th>
                    <th width="150">操作</th>
                </tr>
                </thead>
                {volist name='goods' id='v' empty='$empty'}
                <tbody>
                <tr class="text-c va-m">
                    <td style="vertical-align:middle">
                        <input name="" type="checkbox" value="{$v.id}" class="productCheck">
                    </td>
                    <th width="40" style="vertical-align:middle">{$v.id}</th>
                    <th width="40" style="vertical-align:middle">{$v.goods_id}</th>
                    <td style="vertical-align:middle">
                        <a href="{$v.goods_detail_url}">
                            <img width="60" class="product-thumb" src="{$v.goods_big_img?$v.goods_big_img:$v.goods_detail_url}">
                        </a>
                    </td>
                    <td class="text-1" style="vertical-align:middle">
                        <a href="{$v.goods_detail_url}">
                        {$v.goods_title}
                        </a>
                    </td>
                    <td class="text-1" style="vertical-align:middle">
                       <span style="color: red">{$v.goods_price?$v.goods_price:'无'}元</span>
                    </td>
                    <td class="text-1" style="vertical-align:middle">
                        <span style="color: red">{$v.goods_z_price?$v.goods_z_price:'无'}元</span>
                    </td>
                    <td class="text-1" style="vertical-align:middle">
                        <span style="color: red">{$v.goods_z_price?round($v.goods_z_price/$v.goods_price*100):'无'}</span>
                    </td>
                    <td class="text-1" style="vertical-align:middle">
                        <span style="color: red">{$v.goods_q_price?$v.goods_q_price:'无'}元</span>
                    </td>
                    <td class="text-1" style="vertical-align:middle">
                        <span style="color: red">{$v.coupon_amount?$v.coupon_amount:'0'}元</span>
                    </td>
                    <td class="text-1" style="vertical-align:middle;color: red">{$v.goods_yongjin}</td>
                    <td class="text-1" style="vertical-align:middle;color: red">{$v.goods_yj_rate}</td>
                    <td class="text-1" style="vertical-align:middle;color: red">{$v.goods_volume}</td>
                    <td class="text-1" style="vertical-align:middle;color: red">{$v.goods_user_type==1?'天猫':'淘宝'}</td>
                    <td class="text-1" style="vertical-align:middle;color: red">{$v.browse}</td>

                    <td class="text-1" style="vertical-align:middle">{$v.gt_name?$v.gt_name:'维易超级搜索'}</td>
                    <td class="text-1" style="vertical-align:middle">{$v.gb_name?$v.gb_name:'维易超级搜索'}</td>
                    <td class="text-1" style="vertical-align:middle">{$v.goods_add_time|date='Y-m-d',###}</td>
                    <td class="td-status" style="vertical-align:middle">
                        {if condition="$v.is_down eq 1"}
                        <span class="label label-success radius">已发布</span>
                        {else \}
                        <span class="label label-defaunt radius">已下架</span>
                        {/if}
                    </td>
                    <td class="choice" style="vertical-align:middle">
                        {if condition='$v.is_choice eq 1'}
                            <span class="btn btn-primary radius 	size-MINI" onclick="plain(this,'{$v.goods_id}')">精选</span>
                        {elseif condition='$v.is_choice eq 2' /}
                            <span class="btn btn-success-outline radius 	size-MINI" onclick="choice(this,'{$v.goods_id}')">精选</span>
                        {/if}
                    </td>
                    <td class="td-manage " style="vertical-align:middle">

                        {if condition="$v.is_down eq 1"}
                        <a style="text-decoration:none" onClick="product_stop(this,'{$v.goods_id}')" href="javascript:;" title="下架">
                            <i class="Hui-iconfont">&#xe6de;</i>
                        </a>&nbsp;
                        {else \}
                        <a style="text-decoration:none" onClick="product_start(this,'{$v.goods_id}')" href="javascript:;" title="发布">
                            <i class="Hui-iconfont">&#xe603;</i>
                        </a>&nbsp;
                        {/if}
                       <!-- <a style="text-decoration:none" class="ml-5"  href="javascript:;" onclick="aurora(this,'{$v.goods_id}')" title="推送">
                            <i class="Hui-iconfont">&#xe725;</i><i class="tui">推送</i>
                        </a>;-->

                        <a style="text-decoration:none" class="ml-5" onClick="product_del(this,'{$v.id}')" href="javascript:;" title="删除">
                            <i class="Hui-iconfont">&#xe6e2;</i>
                        </a>


                    </td>
                </tr>
                </tbody>
                {/volist}
            </table>
            <div class="col-md-8 col-xs-6">{$goods->render()}</div>
        </div>

    </div>

</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="__STATIC__/template/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="__STATIC__/template/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="__STATIC__/template/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="__STATIC__/template/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/template/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="__STATIC__/template/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__STATIC__/template/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="__STATIC__/template/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">

    $(document).ready(function(){
        $('#find').click(finduser);//搜索提交
        $('#opt').change(search_item)
    });
    /* 设为精选 */
    function choice(obj,goods_id){
        layer.confirm('是否设为精选商品？',function(index){
            var url = "{:url('admin/goods/choice')}";
            $.post(url,{ goods_id:goods_id }, function (res) {
                console.log(res);
                if(res.ok){
                    $(obj).parents("tr").find(".choice").html('<span class="btn btn-primary radius size-MINI" onclick="plain(this,'+goods_id+')">精选</span>');
                    $(obj).remove();
                    layer.msg(res.msg,{icon:1,time:2000});
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                }
            })

        })
    }
    /*取消精选*/
    function plain(obj,goods_id){
        layer.confirm('是否取消精选商品？',function(index){
            var url = "{:url('admin/goods/plain')}";
            $.post(url,{ goods_id:goods_id }, function (res) {
                console.log(res);
                if(res.ok){
                    $(obj).parents("tr").find(".choice").html('<span class="btn btn-success-outline radius 	size-MINI" onclick="choice(this,'+goods_id+')">精选</span>');
                    $(obj).remove();
                    layer.msg(res.msg,{icon:1,time:2000});
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                }
            })
        })
    }

    /* 搜索 项*/
    function search_item(){
        var opt = $('#opt').val();
        if(opt==1){
            $('#type_s').show();
            $('#goods_title').hide();
            $('#block_s').hide();
            $('#price').hide();
        }else if(opt==2){
            $('#type_s').hide();
            $('#goods_title').show();
            $('#block_s').hide();
            $('#price').hide();
        }
        else if(opt==3){
            $('#type_s').hide();
            $('#goods_title').hide();
            $('#price').hide();
            $('#block_s').show();
        }
        else if(opt==4){
            $('#type_s').hide();
            $('#goods_title').hide();
            $('#block_s').hide();
            $('#price').show();
        }
    }
    /*产品-搜索*/
    function finduser(){
        //alert(1);
        var opt = $('#opt').val();
        var gt_id = $('#goodsType').val();
        var gb_id = $('#gb_id').val();
        var gt_name = $('#goodsType').find('option:selected').text();
        var goods_title = $('#goods_title').val();
        var start_price = $('#start_price').val();
        var end_price = $('#end_price').val();

        var url = "{:url('goods_search')}";

        var data = {
            opt:opt,
            gt_id:gt_id,
            gb_id:gb_id,
            gt_name:gt_name,
            start_price:start_price,
            end_price:end_price,
            goods_title:goods_title
        }
        $.post(url,data,function(result){
           // console.log(result);
            if(result==false){
             layer.msg(result.msg,{icon:1,time:2000});
             }else{
             $("body").empty();
             $("body").append(result);
             if(opt==1){
             $('#type_s').show();
             $('#goods_title').hide();
             $('#block_s').hide();
             $('#price').hide();
             }else if(opt==2){
             $('#type_s').hide();
             $('#goods_title').show();
             $('#block_s').hide();
             $('#price').hide();
             }
             else if(opt==3){
             $('#type_s').hide();
             $('#goods_title').hide();
             $('#price').hide();
             $('#block_s').show();
             }
             else if(opt==4){
             $('#type_s').hide();
             $('#goods_title').hide();
             $('#block_s').hide();
             $('#price').show();
             }
             }

        })

    }
    /* 极光推送 */
    function aurora(obj,goods_id){
       // alert()
        var url = "{:url('admin/Aurora/index')}";
        $.post(url,{ id:goods_id },function(res){
            console.log(res);
            if(res.ok){
                layer.msg(res.msg,{icon:1,time:2000});
               /* $(obj).find('.tui').remove();
                $(obj).find('i').append('<i style="color: red">已推送</i>');*/
            }else{
                layer.msg(res,{icon:5,time:2000});
            }
        })

    }



    /*产品-下架*/
    function product_stop(obj,id){

        layer.confirm('确认要下架吗？',function(index){
            var url = "{:url('stop')}";
            $.post(url,{id:id },function(result){
                console.log(result);
                if(result.ok){
                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="product_start(this,'+id+')" href="javascript:;" title="发布"><i class="Hui-iconfont">&#xe603;</i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
                    $(obj).remove();
                    layer.msg('已下架!',{icon: 5,time:1000});

                }else{
                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="product_stop(this,'+id+')" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已发布</span>');
                    $(obj).remove();
                    layer.msg('下架失败!',{icon: 0,time:1000});
                }
            })

        });
    }

    /*产品-发布*/
    function product_start(obj,id){
        layer.confirm('确认要发布吗？',function(){
            var url = "{:url('start')}";
            $.post(url,{id:id},function(result){
                console.log(result);
                if(result.ok){
                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="product_stop(this,'+id+')" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已发布</span>');
                    $(obj).remove();
                    layer.msg('已发布!',{icon: 6,time:1000});
                }else if(result==2){
                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="product_start(this,'+id+')" href="javascript:;" title="发布"><i class="Hui-iconfont">&#xe603;</i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
                    $(obj).remove();
                    layer.msg('发布失败!',{icon: 5,time:1000});
                }
            })
        });
    }

    /*产品-申请上线*/
    function product_shenqing(obj,id){
        $(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">待审核</span>');
        $(obj).parents("tr").find(".td-manage").html("");
        layer.msg('已提交申请，耐心等待审核!', {icon: 1,time:2000});
    }

    /*产品-删除*/
    function product_del(obj,id){
        layer.confirm('商品将加入过期商品库，确认要删除吗？',function(index){
            var url ="{:url('productDel')}";
            $.post(url,{id:id},function(result){
                console.log(result);
                if(result.ok){
                    $(obj).parents("tr").remove();
                    layer.msg(result.msg,{icon:1,time:1000});
                }else{
                    layer.msg(result.msg,{icon:1,time:2000});
                }
            })

        });
    }
    /*产品-批量删除*/
    function datadel(){
        //alert(1);
        var obj = document.getElementsByClassName('productCheck');
        var num = $('input[type=checkbox]:checked').length;
        if(num==0){
            layer.msg('未选取删除对象！',{icon:0,time:2000});
        }else{
            layer.confirm('批量删除须谨慎，是否删除？',function(){
                var arr = new Array();
                $.each($('input:checkbox:checked'),function(){
                    arr.push(parseInt($(this).val()));
                });
                var data = { id:arr };
                // alert(arr);
                $.post("{:url('admin/Goods/goodsDatadel')}",data,function(result){
                    console.log(result);
                    if(result.ok){
                      //  $(obj).parent("tr").remove();
                        layer.msg(result.msg,{icon:1,time:1000});
                        setTimeout("window.location.replace(location.href)",1000);
                    }else{
                        layer.msg(result.msg,{icon:5,time:1000});
                    }
                });
            });


        }
    }
</script>
</body>
</html>